/*******************************************************************************
 * FilePath    : /Software/Examples_Ble_MS1658/ble_app_peripheral_LED/Src/User/User_Led.c
 * Version     : 1.0
 * Brief       : 
 * Author      : AndrewHu
 * Company     : Shanghai MacroGiga Electronics CO.,Ltd
 * Email       : Hubinbo@macrogiga.com
 * Date        : 2020-04-03 15:15:31
 * LastEditors : AndrewHu
 * LastEditTime: 2021-09-26 14:56:21
 * Description : 
 ******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include <Includes.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static u16 ledDuty[5] = {0x00, 0x00, 0x00, 0x00, 0x00};
/* Private function ----------------------------------------------------------*/
/*******************************************************************************
 * Function    : setLedStatus
 * Brief       : LED亮灭控制
 * Parameter   : x-占空比，最大0xff
 * Returns     : 
 * Date        : 2020-04-03 15:59:24
 * Description : 
 ******************************************************************************/
void setLedStatus(u16 r, u16 g, u16 b, u16 c, u16 w)
{
    // static u16 ledDuty[5] = {0x00, 0x00, 0x00, 0x00, 0x00};

    if (ledDuty[0] != r)
    { //R-change
        ledDuty[0] = r;
        PwmSet_Ch1_R(r);
    }

    if (ledDuty[1] != g)
    { //G-change
        ledDuty[1] = g;
        PwmSet_Ch2_G(g);
    }

    if (ledDuty[2] != b)
    { //B-change
        ledDuty[2] = b;
        PwmSet_Ch3_B(b);
    }

    if (ledDuty[3] != c)
    { //C-change
        ledDuty[3] = c;
        PwmSet_Ch4_C(c);
    }

    if (ledDuty[4] != w)
    { //W-change
        ledDuty[4] = w;
        PwmSet_Ch5_W(w);
    }

    // if (status)
    //     HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_RESET); //low, on
    // else
    //     HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_SET); //high, off
}
/*******************************************************************************
 * Function    : setLedStatusSlow
 * Brief       : 设置灯色，渐变，渐变速度取决于调用周期，每次调整1/x。
 * param        {*}
 * return       {*}
 * Description : 
 * Date        : 2021-09-26 11:25:29
 ******************************************************************************/
void setLedStatusSlow(u16 r, u16 g, u16 b, u16 c, u16 w)
{
    // static u16 ledDuty[5] = {0x00, 0x00, 0x00, 0x00, 0x00};

    if (ledDuty[0] > r)
    { //R-change
        ledDuty[0]--;
        PwmSet_Ch1_R(ledDuty[0]);
    }
    else if (ledDuty[0] < r)
    {
        ledDuty[0]++;
        PwmSet_Ch1_R(ledDuty[0]);
    }

    if (ledDuty[1] > g)
    { //G-change
        ledDuty[1]--;
        PwmSet_Ch2_G(ledDuty[1]);
    }
    else if (ledDuty[1] < g)
    {
        ledDuty[1]++;
        PwmSet_Ch2_G(ledDuty[1]);
    }

    if (ledDuty[2] > b)
    { //B-change
        ledDuty[2]--;
        PwmSet_Ch3_B(ledDuty[2]);
    }
    else if (ledDuty[2] < b)
    { //B-change
        ledDuty[2]++;
        PwmSet_Ch3_B(ledDuty[2]);
    }

    if (ledDuty[3] > c)
    { //C-change
        ledDuty[3]--;
        PwmSet_Ch4_C(ledDuty[3]);
    }
    else if (ledDuty[3] < c)
    { //C-change
        ledDuty[3]++;
        PwmSet_Ch4_C(ledDuty[3]);
    }

    if (ledDuty[4] > w)
    { //W-change
        ledDuty[4]--;
        PwmSet_Ch5_W(ledDuty[4]);
    }
    else if (ledDuty[4] < w)
    { //W-change
        ledDuty[4]++;
        PwmSet_Ch5_W(ledDuty[4]);
    }

    // if (status)
    //     HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_RESET); //low, on
    // else
    //     HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_SET); //high, off
}
/*******************************************************************************
 * Function    : bleLedControl
 * Brief       : 灯控制
 * param        {u8} *data
 * param        {u8} len
 * return       {*}
 * Description : 
 * Date        : 2021-09-23 17:58:18
 ******************************************************************************/
void bleLedControl(u8 *data, u8 len)
{
}
/* extern --------------------------------------------------------------------*/
